$(function() {

	var init = function() {
		$.ajax({
			url: '/api/item/access',
			type: 'get',
			success: function(data) {
				if(data != null && data.length != 0) {
					for(var i = 0; i < data.length; i ++) {
						if(data[i].showValue == "填写" && data[i].value == "true") {
							$("#performanceAdd").attr("checked", true);
						}else if(data[i].showValue == "审核" && data[i].value == "true") {
							$("#perfAudit").attr("checked", true);
						}else if(data[i].showValue == "退回" && data[i].value == "true") {
							$("#performanceBack").attr("checked", true);
						}
					}
				}
			}
		});
	};
	init();
	

	//保存修改
	$("#saveBtn").click(function() {
		var addResult = $("#performanceAdd")[0].checked;
		var auditResult = $("#perfAudit")[0].checked;
		var backResutl = $("#performanceBack")[0].checked;
		var accessList = [];
		
		var accessAdd = {
			type: '权限',
			showValue: '填写',
			value: addResult
		};
		var accessAudit = {
			type: '权限',
			showValue: '审核',
			value: auditResult
		};
		var accessBack = {
			type: '权限',
			showValue: '退回',
			value: backResutl
		};
		accessList.push(accessAdd);
		accessList.push(accessAudit);
		accessList.push(accessBack);
		console.info(accessList);
		$.ajax({
			url: '/api/item/access',
			type: 'post',
			data: {"accessData":accessList, "_t": new Date().getTime()},
			success: function(result) {
				// alert(result);
				if(result == "success") {
					// init();
					bootbox.alert("保存成功！");
				}
			}
		});
	});


});